package caj.springboot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * @description: swagger2配置
 * @author: CAJ
 * @time 2023/10/18 17:09
 *
 * swagger的访问地址为：http://localhost:18080/swagger-ui.html
 * knife4j的访问地址为：http://localhost:18080/doc.html
 *
 * 由于版本原因，swagger和knife4j都不能很好的支持下载相关接口使用，建议直接使用url或postman来完成下载相关功能的测试
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("caj.springboot.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    Contact contact = new Contact(
            "CAJ",
            null,
            null);

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("我的SpringBoot模板")
                .description("这是一个SpringBoot项目模板接口文档")
                .termsOfServiceUrl("") // 用于定义服务的域名（跳转链接）
                .version("1.0")
                .contact(contact)
                .build();
    }

}

